package cn.com.framework;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 
 * 
 * @author Microbun 2012-2-11下午10:43:28
 * @version $Id: ViewInterceptor.java 93 2012-03-10 15:35:24Z Microbun $
 * @since 1.0
 */
public class ViewInterceptor extends HandlerInterceptorAdapter {

	private Logger logger = LoggerFactory.getLogger(ViewInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
//		String localName = request.getRemoteHost();
//		// url绑定
//		if (ConfigUtil.getConfig("localName") == null) {
//			logger.error("没有为服务器配置路径[localName],请在config.properties中进行配置");
//			response.sendError(404);
//		} else if (!ConfigUtil.getConfig("localName").equals(
//				"http://" + localName)) {
//			response.sendError(404);
//		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		if (modelAndView != null) {
			String viewName = modelAndView.getViewName();
			if (viewName.indexOf('/')!=0){
				modelAndView.setViewName("page/" + viewName);
			}else{
				modelAndView.setViewName("page" + viewName);
			}
		}
	}
}
